<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品创建</title>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        h3 {
            color: #333;
            text-align: center;
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #45a049;
        }
        #password {
        width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
    }
    </style>
</head>
<body>
<div class="container">
    <h3>创建商品</h3>
    <div>
        <label>商品名</label>
        <div>
            <input type="text" placeholder="商品名" name="title" id="title">
        </div>
    </div>
    <div>

 <div>
        <label>商品描述</label>
        <div>
            <input type="text" placeholder="商品描述" name="description" id="description">
        </div>
    </div>
    <div>


 <div>
        <label>价格</label>
        <div>
            <input type="text" placeholder="价格" name="price" id="price">
        </div>
    </div>
    <div>


 <div>
        <label>图片</label>
        <div>
            <input type="text" placeholder="图片" name="imgUrl" id="imgUrl">
        </div>
    </div>

 <div>
        <label>库存</label>
        <div>
            <input type="text" placeholder="库存" name="stock" id="stock">
        </div>
    </div>


    <div>
        <button id="create" type="button">
            提交创建
        </button>
    </div>
</div>
</body>
<script>
    jQuery(document).ready(function(){
       $("#create").on("click",function(){
       var title=$("#title").val();
       var description=$("#description").val();
       var price=$("#price").val();
       var stock=$("#stock").val();
       var imgUrl=$("#imgUrl").val();
      
       if(title==null||title==""){
       alert("商品名不能为空")
       return false;
       }

      if(description==null||description==""){
       alert("商品描述不能为空")
       return false;
       }

      if(price==null||price==""){
       alert("价格不能为空")
       return false;
       }

       if(stock==null||stock==""){
       alert("库存不能为空")
       return false;
       }

       if(imgUrl==null||imgUrl==""){
       alert("图片不能为空")
       return false;
       }

          $.ajax({
          type:"POST",
          contentType:"application/x-www-form-urlencoded",
          url:"http://localhost:8090/item/createorder",
          data:{
          "title":title,
          "description":description,
          "price":price,
          "stock":stock,
          "imgUrl":imgUrl,
          },
          xhrFields: {
        withCredentials: true
    },
          success:function(data){
          if(data.status=="success"){
          alert("创建成功")
          window.location.href="/miaoshaoqiangduan/listitem.html";
          }else{
          alert("创建失败，原因为"+data.data.errMsg)
          }
          },
          error:function(data){
          alert("创建失败，原因为"+data.responseText);
          }
          });
          return false;
        });
    });
</script>